<?php
use yii\bootstrap\ActiveForm;
?>
<link rel="stylesheet" href="../static/dist/css/AdminLTE.min.css" type="text/css">
<link rel="stylesheet" href="../static/bootstrap/css/bootstrap.min.css" type="text/css">
<link rel="stylesheet" href="../static/plugins/datatables/jquery.dataTables.css" type="text/css">
<link rel="stylesheet" href="../static/css/admin.css" type="text/css">
<link rel="stylesheet" href="../static/jBox/Skins/Metro/jbox.css" type="text/css">
<link rel="stylesheet" type="text/css" href="../static/app/goods-keyword/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="../static/app/goods-keyword/css/jquery.dropdown.css">
<style>
.dataTables_length {
	margin-top: 10px;
}

.dataTable>tbody>tr>td {
	vertical-align: middle;
	font-size: 0.8em;
	padding: 8px 18px;
}

.dataTable>thead>tr>th {
	vertical-align: middle;
	font-size: 0.8em;
}

.source_type_class {
	min-height: 20px;
	padding-left: 20px;
	margin-bottom: 0;
	font-weight: 400;
	cursor: pointer;
}
.form-left{
    border-right: 1px solid #dddddd;
}

.examine-content{
    width: 1000px;
	margin-left:-300px;
}
.examine-content .input-group .form-control{
    margin-bottom: 20px;
    height: 30px ;
    line-height: 30px;
}
.examine-content button{
    margin: 10px;
}
</style>
<div class="tabs-panel">
	<div class="row">
		<div class="col-xs-12">
			<div class="box">
				<div class="box-header">
					商品名称:	<input class="depart-input" name="search_goods_name_cn" id="search_goods_name_cn" type="text" placeholder="">
					<label>审核状态：</label>
                    <select id="is_examine" name="is_examine" class="depart-input" style="width: 150px">
                        <option value="">全部</option>
                        <?php if (is_array($GLOBALS['_GOODS_EXAMINE_STATUS']) && count($GLOBALS['_GOODS_EXAMINE_STATUS']) > 0)foreach($GLOBALS['_GOODS_EXAMINE_STATUS'] as $key=>$value){?>
                            <option value="<?=$key?>" <?=($key == 1 ? 'selected' : '')?>><?=$value?></option>
                        <?php }?>
                    </select>&nbsp;
					<button type="button" class="btn btn-primary depart-modal" id="select_button" style="width: 100px;">查询</button>
					&nbsp;
					<button type="button" class="btn btn-warning depart-modal" id="reset_button" style="width: 100px;">重置</button>
				</div>
				<div class="box-body">
					<button type="button" class="btn btn-success depart-modal" id="add_goods_button" style="width: 100px;">添加</button>
					<button type="button" class="btn btn-success depart-modal" id="publish_button" style="width: 100px;">同步商品</button>
					<table id="table_id_example" class="display">
						<thead>
							<tr>
								<th style="width: 10%">操作</th>
								<th style="width: 5%">商品ID</th>
								<th style="width: 10%">主商品号</th>
								<th style="width: 10%">商品名称</th>
								<th style="width: 10%">一级分类</th>
								<th style="width: 10%">二级分类</th>
								<th style="width: 10%">商品品类</th>
								<th style="width: 10%">商品品牌</th>
								<th style="width: 5%">排序</th>
								<th style="width: 10%">状态</th>
								<th style="width: 10%">审核状态</th>
							</tr>
						</thead>
						<tbody>
						</tbody>
					</table>
				</div>
			</div>
		</div>
	</div>
</div>
<div class="modal fade" id="add-main-goods-modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
				<h4 class="modal-title" id="myModalLabel_goods">添加商品</h4>
			</div>
			<div class="modal-body">
                <?php
                $form = ActiveForm::begin([
                    'id' => 'add_main_goods_form',
                    'action' => ['/goods/add-main-goods']
                ]);
                ?>
                <div class="box-body">
					<div class="form-group">
						<label for="mobile">商品中文名称</label>
						<input type="text" style="width: 50%;" class="form-control" name="goods_name_cn" id="add_goods_name_cn" placeholder="商品中文名称">
					</div>

					<div class="form-group">
						<label for="mobile">商品其他名称</label>
						<input type="text" style="width: 50%;" class="form-control" name="goods_name_other" id="add_goods_name_other" placeholder="商品其他名称">
					</div>
					<div class="form-group">
						<label for="exampleInputEmail1">商品分类</label> <select
							id="add_category_step1" name="category_step1"
							class="form-control" style="width: 50%;">
							<option value="0">选择商品一级分类</option>
                            <?php foreach($category_list as $value){?>
                                <option value="<?= $value['id']?>"><?= $value['category_name']?></option>
                            <?php }?>
                        </select> <select id="add_category_step2"
							name="category_step2" class="form-control"
							style="width: 50%; margin-top: 10px;">
							<option value="0">选择商品二级分类</option>
						</select>
					</div>
					<div class="form-group">
						<label for="exampleInputEmail1">商品品类</label> <select
							id="add_tag_id" name="tag_id" class="form-control"
							style="width: 50%;">
							<option value="0">选择商品品类</option>
						</select>
					</div>
					<div class="form-group">
						<label for="exampleInputEmail1">商品品牌</label> <select
							id="add_brand_id" name="brand_id" class="form-control"
							style="width: 50%;">
							<option value="0">选择商品品牌</option>
						</select>
					</div>
					<div class="form-group">
						<button type="button"
							class="btn btn-success depart-modal upload-img-btn-main-pic"
							style="width: 110px;">上传商品主图</button>
						<button style="display: none;" data-img="" type="button"
							class="btn btn-success depart-modal show-img-btn-main-pic"
							style="width: 110px;">查看图片</button>
						<input name="goods_main_pic" id="add_goods_main_pic" type="hidden">
					</div>

					<div class="form-group">
						<label for="mobile">图片title</label> <input type="text"
							style="width: 50%;" class="form-control" name="goods_pic_title"
							id="add_goods_pic_title" placeholder="图片title">
					</div>

					<div class="form-group">
						<label for="mobile">图片alt</label> <input type="text"
							style="width: 50%;" class="form-control" name="goods_pic_alt"
							id="add_goods_pic_alt" placeholder="图片alt">
					</div>

					<div class="form-group">
						<label for="mobile">关键字</label><br />
						<button type="button" class="btn btn-success depart-modal"
							id="add_input_keyword" style="width: 100px;">添加</button>
						<table class="table table-hover" id="input_table_keyword">
							<tr>
								<th>关键字</th>
								<th>操作</th>
							</tr>
						</table>
					</div>

					<div class="form-group">
						<label for="exampleInputEmail1">价格单位</label> <select id="add_unit"
							name="unit" class="form-control" style="width: 50%;">
							<option value="CNY">CNY</option>
							<option value="$">$</option>
						</select>
					</div>

					<div class="form-group">
						<label for="mobile">排序</label> <input type="text"
							style="width: 50%;" class="form-control" name="sort"
							id="add_sort" placeholder="排序">
					</div>

					<div class="form-group">
						<label for="exampleInputPassword1">商品中文描述</label>
						<!--                         <textarea class="form-control ckeditor" name="brief_cn" id="add_brief_cn" placeholder="" ></textarea> -->
						<textarea class="form-control xheditor" name="brief_cn"
							id="add_brief_cn" placeholder="" style="width: 100%;"></textarea>
					</div>

					<div class="form-group">
						<label for="exampleInputPassword1">商品其他描述</label>
						<!--                         <textarea class="form-control ckeditor" name="brief_other" id="add_brief_other" placeholder="" ></textarea> -->
						<textarea class="form-control xheditor" name="brief_other"
							id="add_brief_other" placeholder="" style="width: 100%;"></textarea>
					</div>
				</div>

				<input name="add_main_id" id="add_main_id" type="hidden"> <input
					name="add_main_goods_id" id="add_main_goods_id" type="hidden">
				<!-- /.box-body -->

                <?php ActiveForm::end(); ?>
            </div>

			<div style="display: none">
                <?php $form = ActiveForm::begin(['id'=>'upload_goods_main_pic','action'=>'/common/img-upload'],['options' => ['enctype' => 'multipart/form-data']]) ?>
                <?= $form->field($model, 'img_url')->fileInput(['class' => 'upload_file_goods_main_pic']) ?>
                <?php ActiveForm::end() ?>
            </div>

			<div class="modal-footer">
				<button type="button" class="btn btn-default" data-dismiss="modal">关闭
				</button>
				<a type="button" class="btn btn-primary ajax_post_add_goods"> 提交 </a>
			</div>
		</div>
	</div>
</div>

<div class="modal fade" id="examine-goods" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
	<input name="goods_list_edit_id" id="goods_list_edit_id" type="hidden"/> 
	<div class="modal-dialog">
		<div class="modal-content examine-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
				<h4 class="modal-title" id="examine_myModalLabel_goods">审核商品</h4>
			</div>
			<div class="modal-body">
    			<div class="row">
    				<div class="col-md-6 form-left">
    					<form id="examine_goods_form">
                            <div class="box-body">
            					<div class="form-group">
            						<label for="mobile">商品中文名称</label>
            						<input type="text" style="width: 50%;" disabled class="form-control" id="examine_goods_name_cn" name="goods_name_cn" placeholder="商品中文名称">
            					</div>
            					<div class="form-group">
            						<label for="mobile">商品其他名称</label>
            						<input type="text" style="width: 50%;" disabled class="form-control" id="examine_goods_name_other" name="goods_name_other" placeholder="商品其他名称">
            					</div>
            					<div class="form-group">
            						<label for="exampleInputEmail1">商品分类</label>
            						<select id="examine_category_step1" disabled name="category_step1" class="form-control" style="width: 50%;">
            							<option value="0">选择商品一级分类</option>
                                        <?php foreach($category_list as $value){?>
                                       	<option value="<?= $value['id']?>"><?= $value['category_name']?></option>
                                        <?php }?>
                                    </select>
                                    <select id="examine_category_step2" disabled name="category_step2" class="form-control" style="width: 50%; margin-top: 10px;">
            							<option value="0">选择商品二级分类</option>
            						</select>
            					</div>
            					<div class="form-group">
            						<label for="exampleInputEmail1">商品品类</label> 
            						<select id="examine_tag_id" name="tag_id" disabled class="form-control" style="width: 50%;">
            							<option value="0">选择商品品类</option>
            						</select>
            					</div>
            					<div class="form-group">
            						<label for="exampleInputEmail1">商品品牌</label>
            						<select id="examine_brand_id" name="brand_id" disabled class="form-control" style="width: 50%;">
            							<option value="0">选择商品品牌</option>
            						</select>
            					</div>
            					<div class="form-group">
            						<button style="display: none;" data-img="" type="button" class="btn btn-success depart-modal show-img-btn-examine-pic" style="width: 110px;">查看图片</button>
            						<input name="goods_main_pic" id="examine_goods_main_pic" type="hidden">
            					</div>
            					<div class="form-group">
            						<label for="mobile">图片title</label>
            						<input type="text" style="width: 50%;" disabled class="form-control" name="goods_pic_title" id="examine_goods_pic_title" placeholder="图片title">
            					</div>
            
            					<div class="form-group">
            						<label for="mobile">图片alt</label>
            						<input type="text" style="width: 50%;" disabled class="form-control" name="goods_pic_alt" id="examine_goods_pic_alt" placeholder="图片alt">
            					</div>
            
            					<div class="form-group">
            						<label for="mobile">关键字</label><br />
            						<table class="table table-hover" id="examine_input_table_keyword">
            							<tr>
            								<th>关键字</th>
            							</tr>
            						</table>
            					</div>
            
            					<div class="form-group">
            						<label for="exampleInputEmail1">价格单位</label>
            						<select id="examine_unit" name="unit" disabled class="form-control" style="width: 50%;">
            							<option value="CNY">CNY</option>
            							<option value="$">$</option>
            						</select>
            					</div>
            
            					<div class="form-group">
            						<label for="mobile">排序</label>
            						<input type="text" style="width: 50%;" disabled class="form-control" name="sort" id="examine_sort" placeholder="排序">
            					</div>
            
            					<div class="form-group">
            						<label for="exampleInputPassword1">商品中文描述</label>
            						<textarea class="form-control xheditor" name="brief_cn" id="examine_brief_cn" placeholder="" style="width: 100%;"></textarea>
            					</div>
            
            					<div class="form-group">
            						<label for="exampleInputPassword1">商品其他描述</label>
            						<textarea class="form-control xheditor" name="brief_other" id="examine_brief_other" placeholder="" style="width: 100%;"></textarea>
            					</div>
            				</div>
                    	</form>
    				</div>
    				<div class="col-md-6 form-right">
    					<form action="/goods/examine-goods" id="examine_goods_form_2">
                            <div class="box-body">
            					<div class="form-group">
            						<label for="mobile" class="text-danger">原商品中文名称</label>
            						<input type="text" style="width: 50%;" disabled class="form-control" id="examine_goods_name_cn_2" name="goods_name_cn">
            					</div>
            					<div class="form-group">
            						<label for="mobile" class="text-danger">原商品其他名称</label>
            						<input type="text" style="width: 50%;" disabled class="form-control" id="examine_goods_name_other_2" name="goods_name_other">
            					</div>
            					<div class="form-group">
            						<label for="exampleInputEmail1" class="text-danger">原商品分类</label>
            						<select id="examine_category_step1_2" disabled name="category_step1" class="form-control" style="width: 50%;">
         
                                        <?php foreach($category_list as $value){?>
                                       	<option value="<?= $value['id']?>"><?= $value['category_name']?></option>
                                        <?php }?>
                                    </select>
                                    <select id="examine_category_step2_2" disabled name="category_step2" class="form-control" style="width: 50%; margin-top: 10px;">
            						</select>
            					</div>
            					<div class="form-group">
            						<label for="exampleInputEmail1" class="text-danger">原商品品类</label> 
            						<select id="examine_tag_id_2" name="tag_id" disabled class="form-control" style="width: 50%;">
            							<option value="0">选择商品品类</option>
            						</select>
            					</div>
            					<div class="form-group">
            						<label for="exampleInputEmail1" class="text-danger">原商品品牌</label>
            						<select id="examine_brand_id_2" name="brand_id" disabled class="form-control" style="width: 50%;">
            							<option value="0">选择商品品牌</option>
            						</select>
            					</div>
            					<div class="form-group">
            						<button data-img="" type="button" class="btn btn-primary depart-modal show-img-btn-examine-pic_2" style="width: 110px;">查看原图片</button>
            						<input name="goods_main_pic" id="examine_goods_main_pic_2" type="hidden">
            					</div>
            					<div class="form-group">
            						<label for="mobile" class="text-danger">原图片title</label>
            						<input type="text" style="width: 50%;" disabled class="form-control" name="goods_pic_title" id="examine_goods_pic_title_2" placeholder="图片title">
            					</div>
            
            					<div class="form-group">
            						<label for="mobile" class="text-danger">原图片alt</label>
            						<input type="text" style="width: 50%;" disabled class="form-control" name="goods_pic_alt" id="examine_goods_pic_alt_2" placeholder="图片alt">
            					</div>
            
            					<div class="form-group">
            						<label for="mobile" class="text-danger">原关键字</label><br />
            						<table class="table table-hover" id="examine_input_table_keyword_2">
            							<tr>
            								<th>关键字</th>
            							</tr>
            						</table>
            					</div>
            					<div class="form-group">
            						<label for="exampleInputEmail1" class="text-danger">原价格单位</label>
            						<select id="examine_unit_2" name="unit" disabled class="form-control" style="width: 50%;">
            							<option value="CNY">CNY</option>
            							<option value="$">$</option>
            						</select>
            					</div>
            
            					<div class="form-group">
            						<label for="mobile" class="text-danger">原排序</label>
            						<input type="text" style="width: 50%;" disabled class="form-control" name="sort" id="examine_sort_2" placeholder="排序">
            					</div>
            
            					<div class="form-group">
            						<label for="exampleInputPassword1" class="text-danger">原商品中文描述</label>
            						<textarea class="form-control xheditor" name="brief_cn" id="examine_brief_cn_2" placeholder="" style="width: 100%;"></textarea>
            					</div>
            
            					<div class="form-group">
            						<label for="exampleInputPassword1" class="text-danger">原商品其他描述</label>
            						<textarea class="form-control xheditor" name="brief_other" id="examine_brief_other_2" placeholder="" style="width: 100%;"></textarea>
            					</div>
            				</div>
                    	</form>
    				</div>
    				<div class="col-md-12">
                        <div class="col-md-1"></div>
                        <div class="col-md-10">
                        	<button class="btn col-md-3" style="color:#fff;background-color:#df13cd;border-color:#EE00EE" onclick="goodsPreview()">预览</button>
                            <button class="btn btn-warning col-md-3" onclick="changeExamineStatus(3)">核退</button>
                            <button class="btn btn-primary col-md-3" onclick="changeExamineStatus(2)">核准</button>
                        </div>
                        <div class="col-md-1"></div>
                    </div>
    			</div>
            </div>
			<div class="modal-footer">
				<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
			</div>
		</div>
	</div>
</div>

<div class="modal fade" id="add-spec-modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
				<h4 class="modal-title" id="myModalLabel">选择商品规格</h4>
			</div>
			<div class="modal-body">
                <?php $form = ActiveForm::begin(['id' => 'add_sku_form','action' => ['/goods/add-sku']]);?>
				<div class="box-body">
					<div class="nav-tabs-custom">
						<ul class="nav nav-tabs">
                            <?php foreach($spec_group_list as $key=>$value){?>
                                <?php if($key == 0){?>
                                    <li class="active">
                                <?php }else{?>
							<li class="">
                                <?php }?>
                                <a href="#fa-icons-<?= $value['id']?>"
								data-toggle="tab"><?= $value['spec_group_name']?></a>
							</li>
                            <?php }?>
                        </ul>
						<div class="tab-content">
                            <?php foreach($spec_group_list as $key=>$value){?>
                            <?php if($key == 0){?>
                            <div class="tab-pane active"
								id="fa-icons-<?= $value['id']?>">
                                <?php }else{?>
                                <div class="tab-pane"
									id="fa-icons-<?= $value['id']?>">
                                    <?php }?>
                                    <?php if(empty($value['child_list'])){?>
                                    <?php }else{?>
                                        <?php foreach($value['child_list'] as $val){?>
                                            <?php if($value['spec_type'] == 0){?>
                                                <label
										for="spec_id_<?= $val['id']?>"> <input
										id="spec_id_<?= $val['id']?>" name="color_spec_id[]"
										class="spec-class" type="checkbox" value="<?= $val['id']?>">
                                                    <?= $val['spec_val']?>
                                                </label>
                                            <?php }else{?>
                                                <label
										for="spec_id_<?= $val['id']?>"> <input
										id="spec_id_<?= $val['id']?>" name="is_color_spec_id[]"
										class="spec-class" type="checkbox" value="<?= $val['id']?>">
                                                    <?= $val['spec_val']?>
                                                </label>
                                            <?php }?>
                                        <?php }?>
                                    <?php }?>
                                </div>
                                <?php }?>
                            </div>
						</div>
						<input type="hidden" name="add_main_id" id="add_sku_main_id">
						<input type="hidden" name="old_normal_spec_id" id="old_color_spec_id">
						<input type="hidden" name="old_color_spec_id" id="old_is_color_spec_id">
					</div>
                <?php ActiveForm::end(); ?>
				</div>
				<div class="modal-footer">
					<button type="button" class="btn btn-default" data-dismiss="modal">关闭
					</button>
					<a type="button" class="btn btn-primary ajax_post_add_goods_sku">
						提交 </a>
				</div>
			</div>
		</div>
	</div>
</div>

<div class="modal fade" id="show-sku-modal"
	style="background: rgba(236, 230, 230, 0.3);" tabindex="-1"
	role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
	<div class="modal-dialog" style="width: 70%;">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal"
					aria-hidden="true">&times;</button>
				<h4 class="modal-title" id="myModalLabel">商品列表</h4>
			</div>
			<div class="modal-body">
				<div class="box-header">
					<!--<h3 class="box-title">Hover Data Table</h3>-->
					物料号: <input class="depart-input" name="search_goods_sku"
						id="search_goods_sku" type="text" placeholder=""> <input
						class="depart-input" name="select_goods_id" id="select_goods_id"
						type="hidden" value="0">
					<button type="button" class="btn btn-primary depart-modal"
						id="select_goods_button" style="width: 100px;">查询</button>
					&nbsp;
					<button type="button" class="btn btn-warning depart-modal"
						id="reset_goods_button" style="width: 100px;">重置</button>
					<!--部门:<select name="dept_id" id="dept_id"></select>-->
				</div>
				<!-- /.box-header -->
				<div class="box-body">
					<table id="goods_id_example" class="display">
						<thead>
							<tr>
								<th style="width: 30%">操作</th>
								<th>ID</th>
								<th>商品名称</th>
								<th>商品号</th>
								<th>物料号</th>
								<th>规格</th>
								<th>颜色</th>
								<th>排序</th>
								<th>状态</th>
								<th>操作</th>
								<th>审核状态</th>
							</tr>
						</thead>
						<tbody>
						</tbody>
					</table>
				</div>
			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-default" data-dismiss="modal">关闭
				</button>
			</div>
		</div>
		<!-- /.modal-content -->
	</div>
	<!-- /.modal -->
</div>

<div class="modal fade" id="update-sku-modal"
	style="background: rgba(236, 230, 230, 0.3);" tabindex="-1"
	role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
	<div class="modal-dialog" style="width: 40%;">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal"
					aria-hidden="true">&times;</button>
				<h4 class="modal-title" id="myModalLabel">规格详情</h4>
			</div>
			<div class="modal-body">
                <?php
                    
$form = ActiveForm::begin([
                        'id' => 'update_sku_form',
                        'action' => [
                            '/goods/update-goods-sku'
                        ]
                    ]);
                    ?>
                <div class="box-body">
					<div class="form-group">
						<label for="mobile">商品名称</label> <input type="text"
							style="width: 50%;" readonly="readonly" class="form-control"
							name="goods_name_cn" id="update_goods_name_cn"
							placeholder="商品名称">
					</div>

					<div class="form-group">
						<label for="mobile">设为主商品</label>
						<div class="radio">
							<label> <input type="radio" name="is_main" class="is_main_class"
								value="1"> 是
							</label> <label> <input type="radio" name="is_main"
								class="is_main_class" value="0" checked> 否
							</label>
						</div>
					</div>

					<div class="form-group">
						<label for="mobile">物料号</label> <input type="text"
							style="width: 50%;" class="form-control" name="sku"
							id="update_sku" placeholder="物料号">
					</div>

					<div class="form-group">
						<button type="button" class="btn btn-success depart-modal"
							id="add_input" style="width: 100px;">添加</button>
						<label class="source_type_class"> <input type="radio"
							name="is_source_type" class="is_source_type_class" value="0"
							checked> 图片
						</label> <label class="source_type_class"> <input type="radio"
							name="is_source_type" class="is_source_type_class" value="1"> 视频
						</label>

						<table class="table table-hover" id="input_table">
							<tr>
								<th>链接</th>
								<th>操作</th>
							</tr>
						</table>
					</div>


					<div class="form-group">
						<label for="exampleInputEmail1">销售状态</label> <select
							id="update_forsale" name="forsale" class="form-control"
							style="width: 50%;">
							<option value="1">可销售</option>
							<option value="0">不可销售</option>
						</select>
					</div>

					<div class="form-group">
						<label for="mobile">系列号</label> <input type="text"
							style="width: 50%;" class="form-control" name="series"
							id="update_series" placeholder="系列号">
					</div>

					<div class="form-group">
						<label for="mobile">型号</label> <input type="text"
							style="width: 50%;" class="form-control" name="model"
							id="update_model" placeholder="型号">
					</div>

					<div class="form-group">
						<label for="mobile">市场价</label> <input type="text"
							style="width: 50%;" class="form-control" name="market_price"
							id="update_market_price" placeholder="市场价">
					</div>

					<div class="form-group">
						<label for="mobile">销售价</label> <input type="text"
							style="width: 50%;" class="form-control" name="sale_price"
							id="update_sale_price" placeholder="销售价">
					</div>

					<div class="form-group">
						<label for="exampleInputEmail1">上下架</label> <select
							id="update_use_flg" name="use_flg" class="form-control"
							style="width: 50%;">
							<option value="1">上架</option>
							<option value="0">下架</option>
							<option value="2">售罄</option>
						</select>
					</div>
					<input name="check_img_val" type="hidden" id="check_img_val"> <input
						name="update_goods_id" id="update_goods_id" type="hidden">
				</div>
                <?php ActiveForm::end(); ?>
                <div style="display: none">
                    <?php $form = ActiveForm::begin(['id'=>'upload_img_form','action'=>'/common/img-upload'],['options' => ['enctype' => 'multipart/form-data']]) ?>
                    <?= $form->field($model, 'img_url')->fileInput(['class' => 'upload_file']) ?>
                    <?php ActiveForm::end() ?>
                </div>
			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-default" data-dismiss="modal">关闭
				</button>
				<a type="button" class="btn btn-primary ajax_post_update_goods_sku">
					提交 </a>
			</div>
		</div>
	</div>
</div>

<div class="modal fade" id="examine-goods-sku" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
	<input name="goods_sale_edit_id" id="goods_sale_edit_id" type="hidden"/> 
	<div class="modal-dialog">
		<div class="modal-content examine-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
				<h4 class="modal-title">审核子商品</h4>
			</div>
			<div class="modal-body">
    			<div class="row">
    				<div class="col-md-6 form-left">
    					<form>
    						<div class="form-group">
								<label for="mobile">商品名称</label>
								<input type="text" style="width: 50%;" disabled class="form-control" id="sale_goods_name">
        					</div>
        					<div class="form-group">
        						<label for="mobile">设为主商品</label>
        						<div class="radio">
        							<label> <input type="radio" name="sale_product" disabled class="is_main_class" value="1"> 是 </label>
        							<label> <input type="radio" name="sale_product" disabled class="is_main_class" value="0"> 否 </label>
        						</div>
        					</div>
        					<div class="form-group">
        						<label for="mobile">物料号</label>
        						<input type="text" style="width: 50%;" disabled class="form-control" name="sku" id="sale_sku" placeholder="物料号">
        					</div>
        					<div class="form-group">
        						<label for="mobile">图片/视频</label>
        						<table class="table table-hover" id="sale_source">
        							<tr>
        								<th>查看</th>
        							</tr>
        						</table>
        					</div>
        					<div class="form-group">
        						<label for="exampleInputEmail1">销售状态</label>
        						<select id="sale_forsale" name="forsale" disabled class="form-control" style="width: 50%;">
        							<option value="1">可销售</option>
        							<option value="0">不可销售</option>
        						</select>
        					</div>
        
        					<div class="form-group">
        						<label for="mobile">系列号</label>
        						<input type="text" style="width: 50%;" disabled class="form-control" name="series" id="sale_series" placeholder="系列号">
        					</div>
        
        					<div class="form-group">
        						<label for="mobile">型号</label>
        						<input type="text" style="width: 50%;" disabled class="form-control" name="model" id="sale_model" placeholder="型号">
        					</div>
        
        					<div class="form-group">
        						<label for="mobile">市场价</label>
        						<input type="text" style="width: 50%;" disabled class="form-control" name="market_price" id="sale_market_price" placeholder="市场价">
        					</div>
        
        					<div class="form-group">
        						<label for="mobile">销售价</label>
        						<input type="text" style="width: 50%;" disabled class="form-control" name="sale_price" id="sale_price" placeholder="销售价">
        					</div>
        
        					<div class="form-group">
        						<label for="exampleInputEmail1">上下架</label>
        						<select id="sale_use_flg" disabled name="use_flg" class="form-control"
        							style="width: 50%;">
        							<option value="1">上架</option>
        							<option value="0">下架</option>
        							<option value="2">售罄</option>
        						</select>
        					</div>
                    	</form>
    				</div>
    				<div class="col-md-6 form-right">
    					<form>
    						<div class="form-group">
								<label for="mobile">原商品名称</label>
								<input type="text" style="width: 50%;" disabled class="form-control" id="sale_goods_name_2">
        					</div>
        					<div class="form-group">
        						<label for="mobile">原主商品</label>
        						<div class="radio">
        							<label> <input type="radio" name="sale_product_2" disabled class="is_main_class" value="1"> 是 </label>
        							<label> <input type="radio" name="sale_product_2" disabled class="is_main_class" value="0"> 否 </label>
        						</div>
        					</div>
        					<div class="form-group">
        						<label for="mobile">原物料号</label>
        						<input type="text" style="width: 50%;" disabled class="form-control" name="sku" id="sale_sku_2" placeholder="物料号">
        					</div>
        					<div class="form-group">
        						<label for="mobile">原图片/视频</label>
        						<table class="table table-hover" id="sale_source_2">
        							<tr>
        								<th>查看</th>
        							</tr>
        						</table>
        					</div>
        					<div class="form-group">
        						<label for="exampleInputEmail1">原销售状态</label>
        						<select id="sale_forsale_2" name="forsale" disabled class="form-control" style="width: 50%;">
        							<option value="1">可销售</option>
        							<option value="0">不可销售</option>
        						</select>
        					</div>
        
        					<div class="form-group">
        						<label for="mobile">原系列号</label>
        						<input type="text" style="width: 50%;" disabled class="form-control" name="series" id="sale_series_2" placeholder="系列号">
        					</div>
        
        					<div class="form-group">
        						<label for="mobile">原型号</label>
        						<input type="text" style="width: 50%;" disabled class="form-control" name="model" id="sale_model_2" placeholder="型号">
        					</div>
        
        					<div class="form-group">
        						<label for="mobile">原市场价</label>
        						<input type="text" style="width: 50%;" disabled class="form-control" name="market_price" id="sale_market_price_2" placeholder="市场价">
        					</div>
        
        					<div class="form-group">
        						<label for="mobile">原销售价</label>
        						<input type="text" style="width: 50%;" disabled class="form-control" name="sale_price" id="sale_price_2" placeholder="销售价">
        					</div>
        
        					<div class="form-group">
        						<label for="exampleInputEmail1">原上下架</label>
        						<select id="sale_use_flg_2" disabled name="use_flg" class="form-control" style="width: 50%;">
        							<option value="1">上架</option>
        							<option value="0">下架</option>
        							<option value="2">售罄</option>
        						</select>
        					</div>
                    	</form>
    				</div>
    				<div class="col-md-12">
                        <div class="col-md-1"></div>
                        <div class="col-md-10">
                            <button class="btn col-md-3" style="color:#fff;background-color:#df13cd;border-color:#EE00EE" onclick="goodsPreview()">预览</button>
                            <button class="btn btn-warning col-md-3" onclick="changeExamineSkuStatus(3)">核退</button>
                            <button class="btn btn-primary col-md-3" onclick="changeExamineSkuStatus(2)">核准</button>
                        </div>
                        <div class="col-md-1"></div>
                    </div>
    			</div>
            </div>
			<div class="modal-footer">
				<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
			</div>
		</div>
	</div>
</div>
<input name="class_len" id="class_len" value="0" type="hidden" />
<script type="text/javascript" src="../static/plugins/jQuery/jquery-2.2.3.min.js"></script>
<script type="text/javascript" src="../static/bootstrap/js/bootstrap.min.js"></script>
<script type="text/javascript" src="../static/plugins/datatables/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="../static/plugins/datatables/dataTables.bootstrap.min.js"></script>
<script type="text/javascript" src="../static/jBox/jquery.jBox-2.3.min.js"></script>
<script type="text/javascript" src="../static/jBox/i18n/jquery.jBox-zh-CN.js"></script>
<script type="text/javascript" src="/static/plugins/xheditor/xheditor-1.2.2.min.js"></script>
<script type="text/javascript" src="/static/plugins/xheditor/xheditor_lang/zh-cn.js"></script>
<script type="text/javascript" src="../static/plugins/jquery.form.js"></script>
<script type="text/javascript" src="../static/plugins/layer/layer.js"></script>
<script type="text/javascript" src="../static/app/goods-keyword/js/jquery.dropdown.js"></script>
<script type="text/javascript" src="../static/app/goods-keyword/js/mock.js"></script>
<script>
    $(document).ready(function(){
        $('#table_id_example').DataTable({
            dom: '<"top">rt<"bottom"flip><"clear">',
            language: {
                "sUrl":'../static/plugins/datatables/language.json'
            },
            "searching": false,
            "processing": true,
            "serverSide": true,
            ajax:{
                url:'/goods/get-goods-list',
                type:'post',
                data:function(d){
                    d.search_goods_name_cn = $('#search_goods_name_cn').val();
                    d.is_examine = $('#is_examine').val();
                }
            },
            aoColumns: [
                { "data": "", "bSortable": false},
                { "data": "id", "bSortable": true},
                { "data": "main_goods_id", "bSortable": false },
                { "data": "goods_name_cn", "bSortable": false },
                { "data": "category_step1_name", "bSortable": false },
                { "data": "category_step2_name", "bSortable": false },
                { "data": "tag_name", "bSortable": false },
                { "data": "brand_name", "bSortable": false },
                { "data": "sort", "bSortable": true },
                { "data": "use_flg", "bSortable":false },
                { "data": "is_examine", "bSortable":false }
            ],
            columnDefs: [
                {
                    "targets": [0],
                    "orderable":false,
                    "searchable":false,
                    "render": function(data, type, full) {
                        var html = '<a href="javascript:" onclick="updateGoods('+ full.id +')">修改</a>&nbsp;&nbsp;&nbsp;<a href="javascript:" onclick="modSku('+ full.id +')">规格</a>&nbsp;&nbsp;&nbsp;';
                        if(full.is_examine == '1'){
                        	html += '<br/><a href="javascript:" class="text-danger" onclick="goodsExamine('+ full.id +')">审核</a>&nbsp;&nbsp;&nbsp;';
                        }
                        var a_class = '';
                        if(full.sale_need_examine == 1){
                        	a_class = 'text-danger';
                        }
                        html += '<a href="javascript:" class="'+a_class+'" onclick="getSkuList('+ full.id +')">商品列表</a>';
                        return html;
                    }
                },
                {
                    "targets": [1],
                    "orderable":false,
                    "searchable":false,
                    "render": function(data, type, full) {
                        return '<label><input class="publish_class" type="checkbox" name="publish_id[]" value="'+ full.id +'">&nbsp;&nbsp;' + full.id + '</label>';
                    }
                },
                {
                    "targets": [9],
                    "data": "use_flg",
                    "render": function(data, type, full) {
                        var html = '';
                        if(data == 1){
                            html = '<a href="javascript:" onclick="changeMainGoodsStatus('+ full.id +',0)">下架</a>';
                        }else{
                            html = '<a href="javascript:" onclick="changeMainGoodsStatus('+ full.id +',1)">上架</a>';
                        }
                        if(data == 2){
                            return html + '&nbsp;&nbsp;&nbsp;<a href="javascript:">已售罄</a>';
                        }else{
                            return html + '&nbsp;&nbsp;&nbsp;<a href="javascript:" onclick="changeMainGoodsStatus('+ full.id +',2)">售罄</a>';
                        }

                    }
                },
                {
                    "targets": [10],
                    "data": "is_examine",
                    "render": function(data, type, full) {
                        var status = '待审核';
                        var status_class = 'text-danger';
                        if(data == '2'){
                        	status = '核准';
                        	status_class = 'text-primary';
                        }else if(data == '3'){
                        	status = '核退';
                        	status_class = 'text-warning';
                        }
                        return '<span class="'+status_class+'">'+status+'</span>';
                    }
                }
            ],
            order: [[ 1, "desc" ]]
        });

        $('#goods_id_example').DataTable({
            dom: '<"top">rt<"bottom"flip><"clear">',
            language: {
                "sUrl":'../static/plugins/datatables/language.json'
            },
            "searching": false,
            "processing": true,
            "serverSide": true,
            ajax:{
                url:'/goods/get-sku-list',
                type:'post',
                data:function(d){
                    d.select_goods_id = $('#select_goods_id').val();
                    d.search_goods_sku = $('#search_goods_sku').val();
                }
            },
            aoColumns: [
                { "data": "", "bSortable": false},
                { "data": "id", "bSortable": true},
                { "data": "goods_name_cn", "bSortable": false },
                { "data": "goods_id", "bSortable": false },
                { "data": "sku", "bSortable": false },
                { "data": "spec_val", "bSortable": false },
                { "data": "spec_color_val", "bSortable": false },
                { "data": "sort", "bSortable": true },
                { "data": "use_flg", "bSortable": true },
                { "data": "use_flg", "bSortable":false },
                { "data": "is_examine", "bSortable":false }
            ],
            columnDefs: [
                {
                    "targets": [0],
                    "orderable":false,
                    "searchable":false,
                    "render": function(data, type, full) {
                        var html = '<a href="javascript:" onclick="updateGoodsSku('+ full.id +')">修改</a>';
                        if(full.is_examine == '1'){
                        	html += ' | <a href="javascript:" class="text-danger" onclick="examineGoodsSku('+ full.id +')">审核</a>';
                        }
                        return html;
                    }
                },
                {
                    "targets": [8],
                    "orderable":false,
                    "searchable":false,
                    "render": function(data, type, full) {
                        if(data == 2){
                            return '已售罄';
                        }else{
                            return '在售';
                        }
                    }
                },
                {
                    "targets": [9],
                    "data": "use_flg",
                    "render": function(data, type, full) {
                        var html = '';
                        if(data == 1){
                            html = '<a href="javascript:" onclick="changeGoodsStatus('+ full.id +',0)">下架</a>';
                        }else{
                            html = '<a href="javascript:" onclick="changeGoodsStatus('+ full.id +',1)">上架</a>';
                        }
                        /*if(data == 2){
                            return html + '&nbsp;&nbsp;&nbsp;<a href="javascript:">已售罄</a>';
                        }else{
                            return html + '&nbsp;&nbsp;&nbsp;<a href="javascript:" onclick="changeGoodsStatus('+ full.id +',2)">售罄</a>';
                        }*/
                        return html;
                    }
                },
                {
                    "targets": [10],
                    "data": "is_examine",
                    "render": function(data, type, full) {
                    	var status = '待审核';
                        var status_class = 'text-danger';
                        if(data == '2'){
                        	status = '核准';
                        	status_class = 'text-primary';
                        }else if(data == '3'){
                        	status = '核退';
                        	status_class = 'text-warning';
                        }
                        return '<span class="'+status_class+'">'+status+'</span>';
                    }
                }
            ],
            order: [[ 1, "desc" ]]
        });

        //富文本编辑区
//         CKEDITOR.replace('add_brief_cn');
//         CKEDITOR.replace('add_brief_other');
    });

    $('#select_button').click(function(){
        table_list_reload();
    })

    $('#reset_button').click(function(){
        $('#search_goods_name_cn').val('');
        table_list_reload();
    })

    $('#select_goods_button').click(function(){
        goods_list_reload();
    })

    $('#reset_goods_button').click(function(){
        $('#search_goods_sku').val('');
        goods_list_reload();
    })

    //table刷新
    function table_list_reload(){
        var table = $('#table_id_example').DataTable();
        table.ajax.reload();
    }

    function goods_list_reload(){
        var table = $('#goods_id_example').DataTable();
        table.ajax.reload();
    }

    function changeMainGoodsStatus(id,use_flg){
        var title = '';
        if(use_flg == 1){
            title = '确定上架吗？';
        }else if(use_flg == 0){
            title = '确定下架吗？';
        }else{
            title = '确定售罄吗？';
        }
        $.jBox.confirm(title, "提示", function(v){
            if (v == 'ok'){
                $.post('/goods/change-main-goods-status',{id:id,use_flg:use_flg},success,'json');
                return false;
                function success(data){
                    $.jBox.close();                             //关闭对话框
                    if(data.code == 200)
                    {
                        $.jBox.tip('处理成功', 'success');
                        window.setTimeout(function () { table_list_reload(); }, 1000);
                    }
                    else{
                        $.jBox.error(data.val, '错误');
                    }
                }
            }else{
                $.jBox.close();
            }
        });
    }

    $('#table_id_example').on( 'click', '.sorting_1', function () {
        $(this).parent().toggleClass('selected');
        if($(this).parent().hasClass('selected')){
            $(this).find('.publish_class').prop('checked',true);
        }else{
            $(this).find('.publish_class').prop('checked',false);
        }
    } );

    $('#publish_button').click(function(){
        var publish_array = new Array;
        $('.publish_class').each(function(){
            if($(this).is(':checked')){
                publish_array.push($(this).val());
            }
        })
        if(publish_array == '' || publish_array == null || publish_array == undefined){
            $.jBox.error('请选择要同步的商品', '错误');
            return false;
        }
        $.post('/goods/publish-goods',{id:publish_array},success,'json');
        return false;
        function success(data){
            if(data.code == 200)
            {
                $.jBox.tip('处理成功', 'success');
                window.setTimeout(function () { table_list_reload(); }, 1000);
            }
            else{
                $.jBox.error(data.val, '错误');
            }
        }
    })

    //下拉框选择分类，品牌，品类
    var category_child_string = '<?= $category_child_list?>';
var category_child_list = jQuery.parseJSON(category_child_string);

var brand_string = '<?= $brand_list?>';
var brand_list = jQuery.parseJSON(brand_string);

var tag_string = '<?= $tag_list?>';
    var tag_list = jQuery.parseJSON(tag_string);
    $('#add_goods_button').click(function(){
        $('#myModalLabel_goods').html('添加商品');
        resetValue();
        $('#add-main-goods-modal').modal('show');
    })

    $('#add_category_step1').change(function(){
        var add_category_step1 = $('#add_category_step1').val();
        var category_child = category_child_list[add_category_step1];
        var brand = brand_list[add_category_step1];
        $('#add_category_step2').empty();
        $('#add_category_step2').append('<option value="0">选择商品二级分类</option>');
        if(typeof category_child === 'object'){
            for(var i=0;i<category_child.length;i++){
                $('#add_category_step2').append('<option value="'+category_child[i]['id']+'">'+category_child[i]['category_name']+'</option>');
            }
        }

        $('#add_brand_id').empty();
        $('#add_brand_id').append('<option value="0">选择商品品牌</option>');
        if(typeof brand === 'object'){
            for(var i=0;i<brand.length;i++){
                $('#add_brand_id').append('<option value="'+brand[i]['brand_id']+'">'+brand[i]['brand_name']+'</option>');
            }
        }
    })

    $('#add_category_step2').change(function(){
        var add_category_step2 = $('#add_category_step2').val();
        var tag = tag_list[add_category_step2];
        $('#add_tag_id').empty();
        $('#add_tag_id').append('<option value="0">选择商品品类</option>');
        if(typeof tag === 'object'){
            for(var i=0;i<tag.length;i++){
                $('#add_tag_id').append('<option value="'+tag[i]['tag_id']+'">'+tag[i]['tag_name']+'</option>');
            }
        }
    })

    //提交新增商品表单
    $('.ajax_post_add_goods').click(function(){
        var add_goods_name_cn = $('#add_goods_name_cn').val();
        var add_category_step1 = $('add_category_step1').val();
        var add_category_step2 = $('add_category_step2').val();
        var add_tag_id = $('#add_tag_id').val();
        var add_brand_id = $('#add_brand_id').val();
//         var txt_cn = CKEDITOR.instances.add_brief_cn.getData();
//         var txt_other = CKEDITOR.instances.add_brief_other.getData();
        var txt_cn = $('#add_brief_cn').val();
        var txt_other = $('#add_brief_other').val();
        $('#add_brief_cn').text(txt_cn);
        $('#add_brief_other').text(txt_other);

        if(add_goods_name_cn == ''){
            $.jBox.error('请输入商品中文名称', '错误');
            return false;
        }
        if(add_category_step1 == 0){
            $.jBox.error('请选择商品一级分类', '错误');
            return false;
        }
        if(add_category_step2 == 0){
            $.jBox.error('请选择商品二级分类', '错误');
            return false;
        }
        if(add_tag_id == 0){
            $.jBox.error('请选择商品品类', '错误');
            return false;
        }
        if(add_brand_id == 0){
            $.jBox.error('请选择商品品牌', '错误');
            return false;
        }

        $.post($('#add_main_goods_form').attr('action'),$('#add_main_goods_form').serialize(),success,'json');
        return false;
        function success(data){
            if(data.code == 200)
            {
                $.jBox.tip('处理成功', 'success');
                window.setTimeout(function () {
                    $('#add-main-goods-modal').modal('hide');
                    $('#goods_name_cn').val(data.val);
                    var table = $('#table_id_example').DataTable();
                    table.ajax.reload();
                }, 1000);
            }
            else{
                $.jBox.error(data.val, '错误');
            }
        }
    })

    function updateGoods(id){
        resetValue();
        $('#add_main_id').val(id);
        $.post('/goods/get-main-goods-detail',{id:id},success,'json');
        return false;
        function success(data){
            if(data.code == 200)
            {
                setValue(data.val);
                $('#myModalLabel_goods').html('编辑商品');
                $('#add-main-goods-modal').modal('show');
            }
            else{
                $.jBox.error(data.val, '错误');
            }
        }
    }

    function resetValue(){
        $('#add_goods_name_cn').val('');
        $('#add_goods_name_other').val('');
        $('#add_category_step1').val(0);
        $('#add_category_step2').val(0);
        $('#add_tag_id').val(0);
        $('#add_brand_id').val(0);
        $('#add_unit').val('CNY');
        $('#add_sort').val('');
        $('#add_main_id').val('');
        $('#add_goods_main_pic').val('');
        $('#add_goods_pic_title').val('');
        $('#add_goods_pic_alt').val('');
        $('#add_main_goods_id').val('');
        $('.show-img-btn-main-pic').hide();
        $('.show-img-btn-main-pic').attr('data-img','');
        $('#add_brief_cn').val('');
        $('#add_brief_other').val('');
//         CKEDITOR.instances.add_brief_cn.setData('');
//         CKEDITOR.instances.add_brief_other.setData('');
        $('#brief_cn').text('');
        $('#brief_other').text('');
        var html='<tr><th>关键字</th><th>操作</th></tr>';
        $('#input_table_keyword').html(html);
    }

    function setValue(data){
        $('#add_goods_name_cn').val(data['goods_name_cn']);
        $('#add_goods_name_other').val(data['goods_name_other']);
        $('#add_category_step1').val(data['category_step1']);
        if(data['category_step2'] != 0 && data['category_step2'] != null && data['category_step2'] != undefined){
            var category_child = category_child_list[data['category_step1']];
            $('#add_category_step2').empty();
            $('#add_category_step2').append('<option value="0">选择商品二级分类</option>');
            if(typeof category_child === 'object'){
                for(var i=0;i<category_child.length;i++){
                        $('#add_category_step2').append('<option value="'+category_child[i]['id']+'">'+category_child[i]['category_name']+'</option>');
                }
            }
            $('#add_category_step2').val(data['category_step2']);
        }
        if(data['keyword_name'] != '' && data['keyword_name'] != null && data['keyword_name'] != undefined){
        	var akeyword = [];
        	akeyword = data['keyword_name'].split(',');
            var keyword_data = <?=(is_array($keyword) ? json_encode($keyword) : '')?>;
            for (i=0;i<akeyword.length ;i++ ){
            	var html = '';
            	var class_len = $('#class_len').val();
                var div_class = 'dropdown-sin-'+class_len;
//         		html += '<option value="'+akeyword[i]+'">'+akeyword[i]+'</option>';
        		html += '<tr><td>';
            	html += '<div class="'+div_class+'">';
           	 	html += '<select style="display:none" name="keyword[]" placeholder="请选择">';
           	 	if(keyword_data.length > 0){
                	keyword_data.forEach(function(data,index){
                		html += '<option value="'+data.name+'" '+(data.name == akeyword[i] ? 'selected' : '')+'>'+data.name+'</option>';
                    });
           	 	}
            	html += '</select>';
            	html += '</div>';
            	html += '</td>';
            	html += '<td><a class="del_input_table_tr" href="javascript:;">删除</a></td> </tr>';
            	class_len++;
                $('#class_len').val(class_len);
                $('#input_table_keyword').append(html);
                $('.'+div_class).dropdown({
                  readOnly: true,
                  input: '<input type="text" maxLength="20" placeholder="请输入搜索">'
                });
        	}
        }
        if(data['tag_id'] != 0 && data['tag_id'] != null && data['tag_id'] != undefined){
            var tag = tag_list[data['category_step2']];
            $('#add_tag_id').empty();
            $('#add_tag_id').append('<option value="0">选择商品品类</option>');
            if(typeof tag === 'object'){
                for(var i=0;i<tag.length;i++){
                    $('#add_tag_id').append('<option value="'+tag[i]['tag_id']+'">'+tag[i]['tag_name']+'</option>');
                }
            }
            $('#add_tag_id').val(data['tag_id']);
        }
        if(data['brand_id'] != 0 && data['brand_id'] != null && data['brand_id'] != undefined){
            var brand = brand_list[data['category_step1']];
            $('#add_brand_id').empty();
            $('#add_brand_id').append('<option value="0">选择商品品牌</option>');
            if(typeof brand === 'object'){
                for(var i=0;i<brand.length;i++){
                    $('#add_brand_id').append('<option value="'+brand[i]['brand_id']+'">'+brand[i]['brand_name']+'</option>');
                }
            }
            $('#add_brand_id').val(data['brand_id']);
        }
        $('#add_unit').val(data['unit']);
        $('#add_sort').val(data['sort']);
        $('#add_main_id').val(data['id']);
        $('#add_main_goods_id').val(data['main_goods_id']);
        if(data['goods_main_pic'] != 0 && data['goods_main_pic'] != null && data['goods_main_pic'] != undefined){
            $('#add_goods_main_pic').val(data['goods_main_pic']);
            $('.show-img-btn-main-pic').attr('data-img',data['goods_main_pic']);
            $('.show-img-btn-main-pic').show();
        }
        $('#add_goods_pic_title').val(data['goods_pic_title']);
        $('#add_goods_pic_alt').val(data['goods_pic_alt']);
        $('#add_brief_cn').val(data['brief_cn']);
        $('#add_brief_other').val(data['brief_other']);
//         CKEDITOR.instances.add_brief_cn.setData(data['brief_cn']);
//         CKEDITOR.instances.add_brief_other.setData(data['brief_other']);
    }

    function getSkuList(id){
        $('#select_goods_id').val(id);
        var table = $('#goods_id_example').DataTable();
        table.ajax.reload();
        $('#show-sku-modal').modal('show');
    }

    function modSku(id){
        $('.spec-class').each(function(){
            $(this).prop('checked',false);
        })
        $('#add_sku_main_id').val(id);
        $('#old_color_spec_id').val('');
        $('#old_is_color_spec_id').val('');
        $.post('/goods/get-goods-sku',{id:id},success,'json');
        return false;
        function success(data){
            if(data.code == 200)
            {
                var result = data.val;
                var is_checked_spec = result.is_checked_spec;
                var old_color_spec = result.old_color_spec_id;
                var old_is_color_spec_id = result.old_is_color_spec_id;
                if(is_checked_spec != '' && is_checked_spec != null && is_checked_spec != undefined){
                    $('.spec-class').each(function(){
                        var check_val = $(this).val();
                        var check_num = $.inArray(check_val,is_checked_spec);
                        if(eval(check_num) >= 0){
                            $(this).prop('checked',true);
                        }
                    })
                }
                if(old_color_spec != '' && old_color_spec != null && old_color_spec != undefined){
                    $('#old_color_spec_id').val(old_color_spec);
                }
                if(old_is_color_spec_id != '' && old_is_color_spec_id != null && old_is_color_spec_id != undefined){
                    $('#old_is_color_spec_id').val(old_is_color_spec_id);
                }
                $('#add-spec-modal').modal('show');
            }
            else{
                $.jBox.error(data.val, '错误');
            }
        }
    }

    $('.ajax_post_add_goods_sku').click(function(){
        $.post($('#add_sku_form').attr('action'),$('#add_sku_form').serialize(),success,'json');
        return false;
        function success(data){
            if(data.code == 200)
            {
                $.jBox.tip('处理成功', 'success');
                window.setTimeout(function () {
                    $('#add-spec-modal').modal('hide');
                    $('#select_goods_id').val(data.val);
                    var table = $('#goods_id_example').DataTable();
                    table.ajax.reload();
                    $('#show-sku-modal').modal('show');
                }, 1000);
            }
            else{
                $.jBox.error(data.val, '错误');
            }
        }
    })

    function changeGoodsStatus(id,use_flg){
        var title = '';
        if(use_flg == 1){
            title = '确定上架吗？';
        }else if(title == 0){
            title = '确定下架吗？';
        }else{
            title = '确定售罄吗？';
        }
        $.jBox.confirm(title, "提示", function(v){
            if (v == 'ok'){
                $.post('/goods/change-goods-status',{id:id,use_flg:use_flg},success,'json');
                return false;
                function success(data){
                    $.jBox.close();                             //关闭对话框
                    if(data.code == 200)
                    {
                        $.jBox.tip('处理成功', 'success');
                        window.setTimeout(function () {
                            goods_list_reload();
                        }, 1000);
                    }
                    else{
                        $.jBox.error(data.val, '错误');
                    }
                }
            }else{
                $.jBox.close();
            }
        });
    }

function updateGoodsSku(id){
    $('#input_table').empty();
    $('#input_table').append('<tr><th>链接</th><th>操作</th></tr>');
    $('input:radio[name="is_main"][value="0"]').prop('checked',true);
    $('#update_goods_id').val(id);
    $.post('/goods/get-goods-detail',{id:id},success,'json');
    return false;
	function success(data){
    	if(data.code == 200)
        {
            var result = data.val;
            $('#update_goods_name_cn').val(result.goods_name_cn);
            $('#update_sku').val(result.sku);
            $('#update_forsale').val(result.forsale);
            $('#update_market_price').val(result.market_price);
            $('#update_sale_price').val(result.sale_price);
            $('#update_use_flg').val(result.use_flg);
            $('#update_series').val(result.series);
            $('#update_model').val(result.model);
            $('input:radio[name="is_main"][value="'+result.is_main+'"]').prop('checked',true);

            if(result.source_list != '' && result.source_list != null && result.source_list != undefined){
                var source_list = result.source_list;

                for(var i=0;i<source_list.length;i++){
                    var html = '<tr data-length="'+source_list[i]['sort']+'"><td>'+
                    '<input class="input_table_img" value="'+source_list[i]['source_url']+'" name="source_url[]" class="form-control" style="width:100%;">'+
                    '<input class="input_table_sort" value="'+source_list[i]['sort']+'" name="source_sort[]" type="hidden">'+
                    '<input class="input_source_type" value="'+source_list[i]['source_type']+'" name="source_type[]" type="hidden"></td>'+
                    '<td><a href="javascript:;" class="up_input_table_tr">上移</a>'+
                    ' <a href="javascript:;" class="down_input_table_tr">下移</a>'+
                    ' <a class="del_input_table_tr" href="javascript:;">删除</a>';
                    if(source_list[i]['source_type'] == 0){
                        html = html + ' <a class="check_upload_img" href="javascript:;">上传图片</a>' +
                            ' <a class="check_show_img" onclick="showMoreImg('+source_list[i]['sort']+')" img-url="'+source_list[i]['source_url']+'" href="javascript:;">查看图片</a></td> </tr>';
                    }else{
                        html = html + ' <a class="check_upload_video" href="javascript:;">上传视频</a>' +
                            ' <a target="_blank" class="check_show_video" href="<?php echo Yii::$app->params['imageBathUrl'] . '/' ?>'+source_list[i]['source_url']+'">查看视频</a></td> </tr>';
                    }
                    $('#input_table').append(html);
                }
            }
            $('#update-sku-modal').modal('show');
        }else{
            $.jBox.error(data.val, '错误');
        }
    }
}

$('table').delegate('.check_upload_img','click',function(){
    var check_img_val = $(this).parent().parent().attr('data-length');
    $('#check_img_val').val(check_img_val);
    $('.upload_file').trigger('click');
})

$('table').delegate('.check_upload_video','click',function(){
    var check_img_val = $(this).parent().parent().attr('data-length');
    $('#check_img_val').val(check_img_val);
    $('.upload_file').trigger('click');
})

$('.upload_file').change(function(){
    if(this.value != ''){
    	$('#upload_img_form').submit();
    }
})

$('#upload_img_form').submit(function(e){
    e.preventDefault();
    $(this).ajaxSubmit({
        success:function(data){
            var result = $.parseJSON(data);
            if(result.code == 500){
                $.jBox.error(result.val, '错误');
            }else{
                var check_img_val = $('#check_img_val').val();
                $('#input_table').find('tr').each(function(){
                    var table_data_length = $(this).attr('data-length');
                    if(eval(table_data_length) == eval(check_img_val)){
                        var source_type = $(this).find('.input_source_type').val();
                        if(source_type == 0){
                            $(this).find('.input_table_img').val(result.val);
                            $(this).find('a.check_show_img').remove();
                            $(this).find('.check_upload_img').after(' <a class="check_show_img" onclick="showMoreImg('+check_img_val+')" img-url="'+result.val+'" href="javascript:;">查看图片</a>');
                            //$(this).find('.input_table_img').attr('readonly','readonly');
                        }else{
                            $(this).find('.input_table_img').val(result.val);
                            $(this).find('a.check_show_img').remove();
                            $(this).find('.check_upload_video').after(' <a target="_blank" class="check_show_video" href="<?php echo Yii::$app->params['imageBathUrl'] . '/' ?>'+result.val+'">查看视频</a>');
                        }
                    }
                });
                $('#upload_img_form').find('input[type=file]').closest('form').get(0).reset();
            }
        }
    });

});

//查看图片
function showMoreImg(check_img_val){
    var img_url = '';
    $('#input_table').find('tr').each(function(){
        var table_data_length = $(this).attr('data-length');
        if(eval(table_data_length) == eval(check_img_val)){
            img_url = $(this).find('.check_show_img').attr('img-url');
        }
    })
    var json = {
        "title": "分类图片", //相册标题
        "id": 0, //相册id
        "start": 0, //初始显示的图片序号，默认0
        "data": [   //相册包含的图片，数组格式
            {
                "alt": "",//图片名
                "pid": 0, //图片id
                "src": "<?php echo Yii::$app->params['imageBathUrl'] . '/' ?>" + img_url, //原图地址
                "thumb": "" //缩略图地址
            }
        ]
    };
    layer.photos({
        photos: json
    });
}

//添加图片视频
$('#add_input').click(function(){
    var tr_length = $('#input_table').find('tr').length;

    var tr_length_ot = 0;

    $('#input_table').find('tr').each(function(){
        var data_length = $(this).attr('data-length');
        if(data_length != '' && data_length != undefined){
            tr_length_ot = eval(data_length);
        }
    })

    if(eval(tr_length_ot) > 0){
        tr_length = tr_length_ot + 1;
    }

    var is_source_type = $('input:radio[name="is_source_type"]:checked').val();
    var html = '<tr data-length="'+tr_length+'"><td>'+
        '<input class="input_table_img" value="" name="source_url[]" class="form-control" style="width:100%;">'+
        '<input class="input_table_sort" value="'+tr_length+'" name="source_sort[]" type="hidden">'+
        '<input class="input_source_type" value="'+is_source_type+'" name="source_type[]" type="hidden"></td>'+
        '<td><a href="javascript:;" class="up_input_table_tr">上移</a>'+
        ' <a href="javascript:;" class="down_input_table_tr">下移</a>'+
        ' <a class="del_input_table_tr" href="javascript:;">删除</a>';
    if(is_source_type == 0){
        var html = html + ' <a class="check_upload_img" href="javascript:;">上传图片</a></td> </tr>';
    }else{
        var html = html + ' <a class="check_upload_video" href="javascript:;">上传视频</a></td> </tr>';
    }

    $('#input_table').append(html);
})

//添加关键字
$('#add_input_keyword').click(function(){
    var tr_length = $('#input_table_keyword').find('tr').length;

    var tr_length_ot = 0;

    $('#input_table').find('tr').each(function(){
        var data_length = $(this).attr('data-length');
        if(data_length != '' && data_length != undefined){
            tr_length_ot = eval(data_length);
        }
    })

    if(eval(tr_length_ot) > 0){
        tr_length = tr_length_ot + 1;
    }
    var class_len = $('#class_len').val();
    var div_class = 'dropdown-sin-'+class_len;
    var keyword_data = <?=(is_array($keyword) ? json_encode($keyword) : '')?>;
    var html = '<tr><td>';
    	html += '<div class="'+div_class+'">';
   	 	html += '<select style="display:none" name="keyword[]" placeholder="请选择">';
   	 	if(keyword_data.length > 0){
       	 	keyword_data.forEach(function(data,index){
        		html += '<option value="'+data.name+'">'+data.name+'</option>';
            });
       	}
    	html += '</select>';
    	html += '</div>';
    	html += '</td>';
    	html += '<td><a class="del_input_table_tr" href="javascript:;">删除</a></td> </tr>';

    $('#input_table_keyword').append(html);

    $('.'+div_class).dropdown({
      readOnly: true,
      input: '<input type="text" maxLength="20" placeholder="请输入搜索">'
    });
    class_len++;
    $('#class_len').val(class_len);
})

$('table').delegate('.del_input_table_tr','click',function(){
    $(this).parent().parent().remove();
})

$('table').delegate('.up_input_table_tr','click',function(){
    var tr_index = $(this).parent().parent().prev().index();
    if(eval(tr_index) == 0){
        return true;
    }else{
        var obj = $(this).parent().parent().clone();
        $(this).parent().parent().prev().before(obj);
        $(this).parent().parent().remove();
    }

    $('#input_table').find('tr').each(function(){
        var tr_index = $(this).index();
        var data_length = $(this).attr('data-length');
        if(data_length != '' && data_length!= undefined && data_length != 0){
            $(this).attr('data-length',tr_index);
            $(this).find('.input_table_sort').val(tr_index);
        }
    })
})

$('table').delegate('.down_input_table_tr','click',function(){
    var tr_index = $(this).parent().parent().next().index();
    if(eval(tr_index) > eval(-1)){
        var obj = $(this).parent().parent().clone();
        $(this).parent().parent().next().after(obj);
        $(this).parent().parent().remove();
    }

    $('#input_table').find('tr').each(function(){
        var tr_index = $(this).index();
        var data_length = $(this).attr('data-length');
        if(data_length != '' && data_length!= undefined && data_length != 0){
            $(this).attr('data-length',tr_index);
            $(this).find('.input_table_sort').val(tr_index);
        }
    })
})

$('.ajax_post_update_goods_sku').click(function(){
    var update_sku = $('#update_sku').val();
    var update_market_price = $('#update_market_price').val();
    var update_sale_price = $('#update_sale_price').val();

    if(update_sku == ''){
        $.jBox.error('请输入物料号', '错误');
        return false;
    }

    if(update_market_price == '' || update_market_price == '0.00'){
        $.jBox.error('请输入市场价', '错误');
        return false;
    }

    if(update_sale_price == '' || update_sale_price == '0.00'){
        $.jBox.error('请输入销售价', '错误');
        return false;
    }

    $.post($('#update_sku_form').attr('action'),$('#update_sku_form').serialize(),success,'json');
    return false;
    function success(data){
        if(data.code == 200)
        {
            $.jBox.tip('处理成功', 'success');
            window.setTimeout(function () {
                $('#update-sku-modal').modal('hide');
                //$('#select_goods_id').val(data.val);
                var table = $('#goods_id_example').DataTable();
                table.ajax.reload();
            }, 1000);
        }
        else{
            $.jBox.error(data.val, '错误');
        }
    }
})

$('.upload-img-btn-main-pic').click(function(){
    $('.upload_file_goods_main_pic').trigger('click');
})

$('.upload_file_goods_main_pic').change(function(){
    if(this.value == ''){

    }else{
        $('#upload_goods_main_pic').submit();
    }
})

$('#upload_goods_main_pic').submit(function(e){
    e.preventDefault();
    $(this).ajaxSubmit({
        beforeSend:function(){
            /*$('.upload-img-btn').attr('disabled',true);*/
        },
        success:function(data){
            var result = $.parseJSON(data);
            if(result.code == 500){
                $.jBox.error(result.val, '错误');
            }else{
                $('#add_goods_main_pic').val(result.val);
                $('.show-img-btn-main-pic').attr('data-img',result.val);
                $('.show-img-btn-main-pic').show();
                
                $('#upload_goods_main_pic').find('input[type=file]').closest('form').get(0).reset();
            }
        }
    });

});

$('.show-img-btn-main-pic,.show-img-btn-examine-pic,.show-img-btn-examine-pic_2').click(function(){
    var img_url = $(this).attr('data-img');
    showImg(img_url);
})

function showImg(objKey){
    if(objKey == '' || objKey == null || objKey == undefined){
        $.jBox.error('数据为空', '错误');
        return false;
    }
    var json = {
        "title": "分类图片", //相册标题
        "id": 0, //相册id
        "start": 0, //初始显示的图片序号，默认0
        "data": [   //相册包含的图片，数组格式
            {
                "alt": "",//图片名
                "pid": 0, //图片id
                "src": "<?php echo Yii::$app->params['imageBathUrl'] . '/' ?>" + objKey, //原图地址
                "thumb": "" //缩略图地址
            }
        ]
    };
    layer.photos({
        photos: json
    });
}

$("#add_brief_cn , #add_brief_other").xheditor({
	upImgUrl: '/common/xhedit-upload',
	upImgExt: "jpg,jpeg,gif,bmp,png",
	onUpload:insertUpload
},true);

function insertUpload(arrMsg)
{
	var i,msg;
	for(i=0;i<arrMsg.length;i++)
	{
		msg=arrMsg[i];
		$("#xheImgUrl").html(msg);
	}
}

function goodsExamine(id){
	resetExamineValue();
    $.post('/goods/get-examine-goods-detail',{id:id},success,'json');
    return false;
    function success(data){
        if(data.code == 200)
        {
            setExamineValue(data.val);
            $('#examine-goods').modal('show');
        }
        else{
            $.jBox.error(data.val, '错误');
        }
    }
}

function examineGoodsSku(id){
	resetExamineGoodsValue();
    $.post('/goods/get-examine-goods-sku-detail',{id:id},success,'json');
    return false;
    function success(data){
        if(data.code == 200)
        {
            setExamineGoodsValue(data.val);
            $('#examine-goods-sku').modal('show');
        }
        else{
            $.jBox.error(data.val, '错误');
        }
    }
}

function resetExamineValue(){
    $('#examine_goods_name_cn').val('');
    $('#examine_goods_name_other').val('');
    $('#examine_category_step1').val(0);
    $('#examine_category_step2').val(0);
    $('#examine_tag_id').val(0);
    $('#examine_brand_id').val(0);
    $('.show-img-btn-examine-pic').hide();
    $('#examine_goods_pic_title').val('');
    $('#examine_goods_pic_alt').val('');
    var html='<tr><th>关键字</th></tr>';
    $('#examine_input_table_keyword').html(html);
    $('#examine_unit').val('CNY');
    $('#examine_sort').val('');
    $('#examine_brief_cn').val('');
    $('#examine_brief_other').val('');

    $('#examine_goods_name_cn_2').val('');
    $('#examine_goods_name_other_2').val('');
    $('#examine_category_step1_2').val(0);
    $('#examine_category_step2_2').val(0);
    $('#examine_tag_id_2').val(0);
    $('#examine_brand_id_2').val(0);
    $('#examine_goods_pic_title_2').val('');
    $('#examine_goods_pic_alt_2').val('');
    var html='<tr><th>关键字</th></tr>';
    $('#examine_input_table_keyword_2').html(html);
    $('#examine_unit_2').val('CNY');
    $('#examine_sort_2').val('');
    $('#examine_brief_cn_2').val('');
    $('#examine_brief_other_2').val('');

    $('#examine_goods_name_cn_2').parent().css('visibility','hidden');
    $('#examine_goods_name_other_2').parent().css('visibility','hidden');
    $('#examine_category_step1_2').css('visibility','hidden');
    $('#examine_category_step2_2').css('visibility','hidden');
    $('#examine_category_step1_2').parent().css('visibility','hidden');
    $('#examine_tag_id_2').parent().css('visibility','hidden');
    $('#examine_brand_id_2').parent().css('visibility','hidden');
    $('.show-img-btn-examine-pic_2').parent().css('visibility','hidden');
    $('#examine_goods_pic_title_2').parent().css('visibility','hidden');
    $('#examine_goods_pic_alt_2').parent().css('visibility','hidden');
    var html='<tr><th>关键字</th></tr>';
    $('#examine_input_table_keyword_2').html(html);
    $('#examine_input_table_keyword_2').parent().css('visibility','hidden');
    $('#examine_unit_2').parent().css('visibility','hidden');
    $('#examine_sort_2').parent().css('visibility','hidden');
    $('#examine_brief_cn_2').parent().css('visibility','hidden');
    $('#examine_brief_other_2').parent().css('visibility','hidden');
}

function setExamineValue(data){
	var new_data = data.new_data;
	var old_data = data.old_data;
    $('#examine_goods_name_cn').val(new_data['goods_name_cn']);
    $('#examine_goods_name_other').val(new_data['goods_name_other']);
    $('#examine_category_step1').val(new_data['category_step1']);
    if(new_data['category_step2'] != 0 && new_data['category_step2'] != null && new_data['category_step2'] != undefined){
        var category_child = category_child_list[new_data['category_step1']];
        $('#examine_category_step2').empty();
        $('#examine_category_step2').append('<option value="0">选择商品二级分类</option>');
        if(typeof category_child === 'object'){
            for(var i=0;i<category_child.length;i++){
				$('#examine_category_step2').append('<option value="'+category_child[i]['id']+'">'+category_child[i]['category_name']+'</option>');
            }
        }
        $('#examine_category_step2').val(new_data['category_step2']);
    }
    if(new_data['tag_id'] != 0 && new_data['tag_id'] != null && new_data['tag_id'] != undefined){
        var tag = tag_list[new_data['category_step2']];
        $('#examine_tag_id').empty();
        $('#examine_tag_id').append('<option value="0">选择商品品类</option>');
        if(typeof tag === 'object'){
            for(var i=0;i<tag.length;i++){
                $('#examine_tag_id').append('<option value="'+tag[i]['tag_id']+'">'+tag[i]['tag_name']+'</option>');
            }
        }
        $('#examine_tag_id').val(new_data['tag_id']);
    }
    if(new_data['brand_id'] != 0 && new_data['brand_id'] != null && new_data['brand_id'] != undefined){
        var brand = brand_list[new_data['category_step1']];
        $('#examine_brand_id').empty();
        $('#examine_brand_id').append('<option value="0">选择商品品牌</option>');
        if(typeof brand === 'object'){
            for(var i=0;i<brand.length;i++){
                $('#examine_brand_id').append('<option value="'+brand[i]['brand_id']+'">'+brand[i]['brand_name']+'</option>');
            }
        }
        $('#examine_brand_id').val(new_data['brand_id']);
    }
    if(new_data['goods_main_pic'] != 0 && new_data['goods_main_pic'] != null && new_data['goods_main_pic'] != undefined){
        $('.show-img-btn-examine-pic').attr('data-img',new_data['goods_main_pic']);
        $('.show-img-btn-examine-pic').show();
    }
    $('#examine_goods_pic_title').val(new_data['goods_pic_title']);
    $('#examine_goods_pic_alt').val(new_data['goods_pic_alt']);
    var akeyword = [];
    var akeyword_old = [];
    if(old_data && old_data != '' && old_data != null){
    	if(old_data['keyword_name'] && old_data['keyword_name'] != new_data['keyword_name']){
        	akeyword_old = old_data['keyword_name'].split(',');
        }
    }
	var keyword_data = <?=(is_array($keyword) ? json_encode($keyword) : '')?>;
    if(new_data['keyword_name'] != '' && new_data['keyword_name'] != null && new_data['keyword_name'] != undefined){
    	akeyword = new_data['keyword_name'].split(',');
        for (i=0;i<akeyword.length ;i++ ){
        	var html = '';
        	var class_len = $('#class_len').val();
            var div_class = 'dropdown-sin-'+class_len;
    		html += '<tr><td>';
        	html += '<div class="'+div_class+'">';
       	 	html += '<select disabled name="keyword[]" style="width:50%" class="form-control" placeholder="请选择">';
       	 	if(keyword_data.length > 0){
            	keyword_data.forEach(function(data,index){
            		html += '<option value="'+data.name+'" '+(data.name == akeyword[i] ? 'selected' : '')+'>'+data.name+'</option>';
                });
       	 	}
        	html += '</select>';
        	html += '</div>';
        	html += '</td></tr>';
        	class_len++;
            $('#class_len').val(class_len);
            $('#examine_input_table_keyword').append(html);
    	}
        if(akeyword_old.length > akeyword.length){
    		for (i=0;i<akeyword_old.length-akeyword.length;i++ ){
        		var html = '';
        		html = '<tr style="visibility: hidden;"><td><div><select disabled name="keyword[]" style="width:50%" class="form-control" placeholder="请选择"></select><div/></td></tr>'
        		$('#examine_input_table_keyword').append(html);
        	}
       	}
    }else{
    	var html = '';
    	for (i=0;i<akeyword_old.length ;i++ ){
    		html += '<tr style="visibility: hidden;"><td><div><select disabled name="keyword[]" style="width:50%" class="form-control" placeholder="请选择"></select><div/></td></tr>'
    	}
    	$('#examine_input_table_keyword').append(html);
    }
    $('#examine_unit').val(new_data['unit']);
    $('#examine_sort').val(new_data['sort']);
    $('#examine_brief_cn').val(new_data['brief_cn']);
    $('#examine_brief_other').val(new_data['brief_other']);
    //原始数据
    if(old_data && old_data != '' && old_data != null){
    	if(old_data['goods_name_cn'] != new_data['goods_name_cn']){
        	$('#examine_goods_name_cn_2').val(old_data['goods_name_cn']);
        	$('#examine_goods_name_cn_2').parent().removeAttr('style');
       	}else{
       		$('#examine_goods_name_cn_2').parent().css('visibility','hidden');
       	}
    	if(old_data['goods_name_other'] != new_data['goods_name_other']){
        	$('#examine_goods_name_other_2').val(old_data['goods_name_other']);
        	$('#examine_goods_name_other_2').parent().removeAttr('style');
       	}else{
       		$('#examine_goods_name_other_2').parent().css('visibility','hidden');
       	}
    	if(old_data['category_step1'] != new_data['category_step1']){
        	$('#examine_category_step1_2').val(old_data['category_step1']);
        	$('#examine_category_step1_2').removeAttr('style');
       	}else{
       		$('#examine_category_step1_2').css('visibility','hidden');
       	}
    	if(old_data['category_step2'] != new_data['category_step2']){
        	$('#examine_category_step2_2').val(old_data['category_step2']);
        	$('#examine_category_step2_2').removeAttr('style');
       	}else{
       		$('#examine_category_step2_2').css('visibility','hidden');
       	}
       	if(old_data['category_step1'] == new_data['category_step1'] && old_data['category_step2'] == new_data['category_step2']){
           	$('#examine_category_step1_2').parent().css('visibility','hidden');
        }else{
        	$('#examine_category_step1_2').parent().removeAttr('style');
       	}
       	if(old_data['tag_id'] != new_data['tag_id']){
        	$('#examine_tag_id_2').val(old_data['tag_id']);
        	$('#examine_tag_id_2').parent().removeAttr('style');
       	}else{
       		$('#examine_tag_id_2').parent().css('visibility','hidden');
       	}
       	if(old_data['brand_id'] != new_data['brand_id']){
        	$('#examine_brand_id_2').val(old_data['brand_id']);
        	$('#examine_brand_id_2').parent().removeAttr('style');
       	}else{
       		$('#examine_brand_id_2').parent().css('visibility','hidden');
       	}
       	if(old_data['goods_main_pic'] != new_data['goods_main_pic']){
       		$('.show-img-btn-examine-pic_2').attr('data-img',old_data['goods_main_pic']);
       		$('.show-img-btn-examine-pic_2').parent().removeAttr('style');
       	}else{
       		$('.show-img-btn-examine-pic_2').parent().css('visibility','hidden');
       	}
       	if(old_data['goods_pic_title'] != new_data['goods_pic_title']){
       		$('#examine_goods_pic_title_2').val(old_data['goods_pic_title']);
       		$('#examine_goods_pic_title_2').parent().removeAttr('style');
       	}else{
       		$('#examine_goods_pic_title_2').parent().css('visibility','hidden');
       	}
       	if(old_data['goods_pic_alt'] != new_data['goods_pic_alt']){
       		$('#examine_goods_pic_alt_2').val(old_data['goods_pic_alt']);
       		$('#examine_goods_pic_alt_2').parent().removeAttr('style');
       	}else{
       		$('#examine_goods_pic_alt_2').parent().css('visibility','hidden');
       	}
       	if(old_data['keyword_name'] != new_data['keyword_name']){
           	if(old_data['keyword_name']){
                for (i=0;i<akeyword_old.length ;i++ ){
                	var html = '';
                	var class_len = $('#class_len').val();
                    var div_class = 'dropdown-sin-'+class_len;
            		html += '<tr><td>';
                	html += '<div class="'+div_class+'">';
               	 	html += '<select disabled name="keyword[]" style="width:50%" class="form-control" placeholder="请选择">';
               	 	if(keyword_data.length > 0){
                    	keyword_data.forEach(function(data,index){
                    		html += '<option value="'+data.name+'" '+(data.name == akeyword_old[i] ? 'selected' : '')+'>'+data.name+'</option>';
                        });
               	 	}
                	html += '</select>';
                	html += '</div>';
                	html += '</td></tr>';
                	class_len++;
                    $('#class_len').val(class_len);
                    $('#examine_input_table_keyword_2').append(html);
            	}
            	if(akeyword.length > akeyword_old.length){
            		for (i=0;i<akeyword.length-akeyword_old.length;i++){
                		var html = '';
                		html = '<tr style="visibility: hidden;"><td><div><select disabled name="keyword[]" style="width:50%" class="form-control" placeholder="请选择"></select><div/></td></tr>'
                		$('#examine_input_table_keyword_2').append(html);
                	}
               	}
            }else{
                var html = '';
            	for (i=0;i<akeyword.length ;i++ ){
            		html += '<tr style="visibility: hidden;"><td><div><select disabled name="keyword[]" style="width:50%" class="form-control" placeholder="请选择"></select><div/></td></tr>'
            	}
            	$('#examine_input_table_keyword_2').append(html);
            }
            $('#examine_input_table_keyword_2').parent().removeAttr('style');
       	}else{
       		$('#examine_input_table_keyword_2').parent().css('visibility','hidden');
       	}
       	if(old_data['unit'] != new_data['unit']){
       		$('#examine_unit_2').val(old_data['unit']);
       		$('#examine_unit_2').parent().removeAttr('style');
       	}else{
       		$('#examine_unit_2').parent().css('visibility','hidden');
       	}
       	if(old_data['sort'] != new_data['sort']){
       		$('#examine_sort_2').val(old_data['sort']);
       		$('#examine_sort_2').parent().removeAttr('style');
       	}else{
       		$('#examine_sort_2').parent().css('visibility','hidden');
       	}
       	if(old_data['brief_cn'] != new_data['brief_cn']){
       		$('#examine_brief_cn_2').val(old_data['brief_cn']);
       		$('#examine_brief_cn_2').parent().removeAttr('style');
       	}else{
       		$('#examine_brief_cn_2').parent().css('visibility','hidden');
       	}
    	if(old_data['brief_other'] != new_data['brief_other']){
       		$('#examine_brief_other_2').val(old_data['brief_other']);
       		$('#examine_brief_other_2').parent().removeAttr('style');
       	}else{
       		$('#examine_brief_other_2').parent().css('visibility','hidden');
       	}
    }
    $('#goods_list_edit_id').val(new_data['id']);
}

function resetExamineGoodsValue(){
    $('#sale_goods_name').val('');
    $('#examine-goods-sku').find('input[name=sale_product]').prop('checked',false);
    $('#sale_sku').val('');
    $('#sale_forsale').val(0);
    $('#sale_series').val('');
    $('#sale_model').val('');
    $('#sale_market_price').val('');
    $('#sale_price').val('');
    $('#sale_use_flg').val(1);

    $('#sale_goods_name_2').val('');
    $('#examine-goods-sku').find('input[name=sale_product_2]').prop('checked',false);
    $('#sale_sku_2').val('');
    $('#sale_forsale_2').val(0);
    $('#sale_series_2').val('');
    $('#sale_model_2').val('');
    $('#sale_market_price_2').val('');
    $('#sale_price_2').val('');
    $('#sale_use_flg_2').val(1);

    $('#sale_goods_name_2').parent().css('visibility','hidden');
    $('#examine-goods-sku').find('input[name=sale_product_2]').parent().parent().parent().css('visibility','hidden');
    $('#sale_sku_2').parent().css('visibility','hidden');
    $('#sale_forsale_2').parent().css('visibility','hidden');
    $('#sale_series_2').parent().css('visibility','hidden');
    $('#sale_model_2').parent().css('visibility','hidden');
    $('#sale_market_price_2').parent().css('visibility','hidden');
    $('#sale_price_2').parent().css('visibility','hidden');
    $('#sale_use_flg_2').parent().css('visibility','hidden');
    $('#sale_source_2').parent().css('visibility','hidden');
}

function setExamineGoodsValue(data){
	var new_data = data.new_data;
	var old_data = data.old_data;
    $('#sale_goods_name').val(new_data['goods_name_cn']);
    $('#examine-goods-sku').find('input[name=sale_product][value='+new_data['sale_product']+']').prop('checked',true);
    $('#sale_sku').val(new_data['sku']);
    $('#sale_forsale').val(new_data['forsale']);
    $('#sale_series').val(new_data['series']);
    $('#sale_model').val(new_data['model']);
    $('#sale_market_price').val(new_data['market_price']);
    $('#sale_price').val(new_data['sale_price']);
    $('#sale_use_flg').val(new_data['use_flg']);
    var goods_source_old = [];
    var goods_source = [];
    if(old_data && old_data != '' && old_data != null){
    	if(old_data['goods_source'].length > 0){
    		goods_source_old = old_data['goods_source'];
    	}
    }
    if(new_data['goods_source'].length > 0){
        goods_source = new_data['goods_source'];
        for (i=0;i<goods_source.length ;i++ ){
        	var html = '';
    		html += '<tr><td><a href="javascript:;" img-url="'+goods_source[i].source_url+'" onclick="showMoreImg(1)" class="check_show_img">查看图片</a></td></tr>';
            $('#sale_source').append(html);
    	}
        if(goods_source_old.length > goods_source.length){
    		for (i=0;i<goods_source_old.length-goods_source.length;i++ ){
        		var html = '';
        		html = '<tr style="visibility: hidden;"><td></td></tr>'
        		$('#sale_source').append(html);
        	}
       	}
    }else{
    	var html = '';
    	for (i=0;i<akeyword_old.length ;i++ ){
    		html += '<tr style="visibility: hidden;"><td></td></tr>'
    	}
    	$('#sale_source').append(html);
    }
    //原始数据
    if(old_data && old_data != '' && old_data != null){
    	if(old_data['goods_name_cn'] != new_data['goods_name_cn']){
        	$('#sale_goods_name_2').val(old_data['goods_name_cn']);
        	$('#sale_goods_name_2').parent().removeAttr('style');
       	}else{
       		$('#sale_goods_name_2').parent().css('visibility','hidden');
       	}
    	if(old_data['sale_product'] != new_data['sale_product']){
    		$('#examine-goods-sku').find('input[name=sale_product_2][value='+old_data['sale_product']+']').prop('checked',true);
    		$('#examine-goods-sku').find('input[name=sale_product_2]').parent().parent().parent().removeAttr('style');
       	}else{
       		$('#examine-goods-sku').find('input[name=sale_product_2]').parent().parent().parent().css('visibility','hidden');
       	}
    	if(old_data['sku'] != new_data['sku']){
        	$('#sale_sku_2').val(old_data['sku']);
        	$('#sale_sku_2').parent().removeAttr('style');
       	}else{
       		$('#sale_sku_2').parent().css('visibility','hidden');
       	}
    	if(old_data['forsale'] != new_data['forsale']){
        	$('#sale_forsale_2').val(old_data['forsale']);
        	$('#sale_forsale_2').parent().removeAttr('style');
       	}else{
       		$('#sale_forsale_2').parent().css('visibility','hidden');
       	}
       	if(old_data['series'] != new_data['series']){
        	$('#sale_series_2').val(old_data['series']);
        	$('#sale_series_2').parent().removeAttr('style');
       	}else{
       		$('#sale_series_2').parent().css('visibility','hidden');
       	}
       	if(old_data['model'] != new_data['model']){
        	$('#sale_model_2').val(old_data['model']);
        	$('#sale_model_2').parent().removeAttr('style');
       	}else{
       		$('#sale_model_2').parent().css('visibility','hidden');
       	}
       	if(old_data['market_price'] != new_data['market_price']){
       		$('#sale_market_price_2').val(old_data['market_price']);
       		$('#sale_market_price_2').parent().removeAttr('style');
       	}else{
       		$('#sale_market_price_2').parent().css('visibility','hidden');
       	}
       	if(old_data['sale_price'] != new_data['sale_price']){
       		$('#sale_price_2').val(old_data['sale_price']);
       		$('#sale_price_2').parent().removeAttr('style');
       	}else{
       		$('#sale_price_2').parent().css('visibility','hidden');
       	}
       	if(old_data['use_flg'] != new_data['use_flg']){
       		$('#sale_use_flg_2').val(old_data['use_flg']);
       		$('#sale_use_flg_2').parent().removeAttr('style');
       	}else{
       		$('#sale_use_flg_2').parent().css('visibility','hidden');
       	}
       	var num = 0;
       	if(goods_source_old.length > 0){
            for (i=0;i<goods_source_old.length ;i++ ){
            	var html = '';
                if(goods_source_old[i].source_url != goods_source[i].source_url){
                	num ++;
            		html += '<tr><td><a href="javascript:;" img-url="'+goods_source_old[i].source_url+'" onclick="showMoreImg(1)" class="check_show_img">查看图片</a></td></tr>';
                    $('#sale_source_2').append(html);
                }else{
            		html = '<tr style="visibility: hidden;"><td>--</td></tr>'
            		$('#sale_source_2').append(html);
                }
        	}
        	if(goods_source.length > goods_source_old.length){
        		for (i=0;i<goods_source.length-goods_source_old.length;i++){
            		var html = '';
            		html = '<tr style="visibility: hidden;"><td>--</td></tr>'
            		$('#sale_source_2').append(html);
            	}
           	}
        }else{
        	$('#sale_source_2').parent().css('visibility','hidden');
        }
        if(num != 0){
			$('#sale_source_2').parent().removeAttr('style');
        }else{
            $('#sale_source_2').parent().css('visibility','hidden');
        }
    }
    $('#goods_sale_edit_id').val(new_data['id']);
}

function changeExamineStatus(status){
	var id = $('#goods_list_edit_id').val();
	$.post('/goods/examine-goods',{status:status,id:id},success,'json');
    return false;
    function success(data){
        if(data.code == 200)
        {
            $.jBox.tip('处理成功', 'success');
            window.setTimeout(function () {
                $('#examine-goods').modal('hide');
                table_list_reload();
            }, 1000);
        }
        else{
            $.jBox.error(data.val, '错误');
        }
    }
}

function changeExamineSkuStatus(status){
	var id = $('#goods_sale_edit_id').val();
	$.post('/goods/examine-goods-sku',{status:status,id:id},success,'json');
    return false;
    function success(data){
        if(data.code == 200)
        {
            $.jBox.tip('处理成功', 'success');
            window.setTimeout(function () {
                $('#examine-goods-sku').modal('hide');
                goods_list_reload();
            }, 1000);
        }
        else{
            $.jBox.error(data.val, '错误');
        }
    }
}
</script>